export default class orc_net extends Laya.Script {
    /** @prop {name:intType, tips:"整数类型示例", type:Int, default:1000}*/
    public intType: number = 1000;
    /** @prop {name:numType, tips:"数字类型示例", type:Number, default:1000}*/
    public numType: number = 1000;
    /** @prop {name:strType, tips:"字符串类型示例", type:String, default:"hello laya"}*/
    public strType: string = "hello laya";
    /** @prop {name:boolType, tips:"布尔类型示例", type:Bool, default:true}*/
    public boolType: boolean = true;
    // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
    
    constructor() { super(); }
    
    public static async http_post(url:string,params:any){
        return new Promise((resolve,reject)=>{
            var xhr: Laya.HttpRequest = new Laya.HttpRequest();        
            xhr.http.timeout = 10000;//设置超时时间；
            let url_temp:string;
            if(orc.orc_config.DEBUG == true)
            {
                url_temp= orc.orc_config.HTTP_TEST_URL + url;
            }
            else
            {
                url_temp= orc.orc_config.HTTP_ONLINE_URL + url;
            }
            params = orc.orc_utils.json_to_substr(params);
            console.log('params:',params);
            xhr.send(url_temp,params, "post", "text");

            xhr.once(Laya.Event.COMPLETE, this, (respone)=>{
                let result = JSON.parse(respone);
                console.log('http server:',url_temp,result);
                resolve(result);
            });
            xhr.once(Laya.Event.ERROR, this, (respone)=>{
                resolve('timeout');
            });
            xhr.on(Laya.Event.PROGRESS, this,(respone)=>{
                resolve('timeout');
            });
           
        })       
    }

   
}